//多次询问，用floyd算法
//时间复杂度:O(n^3)
//理念是dp的理念
//

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

int n, m, k;
const int N = 210, INF = 1e9;
int g[N][N];

void floyd()
{
    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m >> k;
    //先初始化一下邻接矩阵
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            if(i == j) g[i][j] = 0;
            else g[i][j] = INF;
    for(int i = 0; i < m; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        //保留最小边即可
        if(a!=b) g[a][b] = min(g[a][b], c);
    }
    floyd();
    while(k--)
    {
        int a, b;
        cin >> a >> b;
        if(g[a][b] > INF /2 ) cout << "impossible\n";
        else cout << g[a][b] << endl;
    }
    return 0;
}
